Skip to content

Conversation

ankith26
Copy link
Member

@ankith26 ankith26 commented Sep 1, 2025

  • display index compat code
  • fullscreen compat code unified
  • syncwindow calls so that changes take immediate affect like sdl2

@ankith26 ankith26 requested a review from a team as a code owner September 1, 2025 14:16
Copy link
Contributor

coderabbitai bot commented Sep 1, 2025

📝 Walkthrough

Walkthrough

Adds SDL3-focused updates: a boolean GL swap-interval wrapper, primary-display resolution in display APIs, a unified boolean fullscreen helper, and widespread SDL_SyncWindow calls after window/display state changes. Adjusts message box return checks and refactors GL attribute set/get wrappers for SDL3 semantics. SDL2 paths remain guarded and compatible.

Changes

Cohort / File(s) Summary
SDL3 GL wrappers and aliases
src_c/_pygame.h
Adds PG_GL_SetSwapInterval wrapper (boolean) mapped to SDL3’s SDL_GL_SetSwapInterval; adds macro alias in SDL3 path; no SDL2 changes.
Display management, primary display resolution, fullscreen unification
src_c/display.c
Introduces primary-display lookup (SDL_GetPrimaryDisplay) instead of assuming index 0; updates pg_get_active null-check; refactors fullscreen handling via boolean PG_SetWindowFullscreen; replaces direct GL swap-interval and GL attribute calls with wrappers; adds SDL_SyncWindow in SDL3 paths; adjusts SDL_ShowMessageBox boolean check for SDL3.
Window state synchronization and SDL3 return semantics
src_c/window.c
Adds SDL_SyncWindow after window operations in SDL3 (restore/maximize/minimize/resize/constraints/position/fullscreen transitions); adapts fullscreen/windowed paths to SDL3 boolean returns; minor variable/type adjustments in focus handling for SDL3.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor App
  participant Display as Display API
  participant SDL as SDL (SDL2/SDL3)
  participant Win as SDL_Window

  rect rgba(200,230,255,0.3)
  note over App,SDL: Set video mode / toggle fullscreen (SDL3 path)
  App->>Display: pg_set_mode(...) / pg_toggle_fullscreen(...)
  Display->>SDL: PG_SetWindowFullscreen(Win, fullscreen, non_desktop)
  alt SDL3
    SDL-->>Display: bool success/failure
    Display->>SDL: SDL_SyncWindow(Win)
  else SDL2
    SDL-->>Display: int (0 on success)
  end
  Display-->>App: result
  end

  rect rgba(220,255,220,0.3)
  note over App,SDL: VSync configuration (SDL3 path)
  App->>Display: set vsync (-1/0/1)
  Display->>SDL: PG_GL_SetSwapInterval(interval)
  SDL-->>Display: bool success/failure
  Display-->>App: result
  end

  rect rgba(255,240,200,0.3)
  note over App,SDL: Primary display resolution (SDL3 path)
  App->>Display: list_modes/mode_ok/get_video_info
  Display->>SDL: SDL_GetPrimaryDisplay()
  SDL-->>Display: primary_display index/handle
  Display->>SDL: Query modes for primary_display
  SDL-->>Display: modes / errors
  Display-->>App: data or raised error
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • Port display.c to SDL3 #3428: Also updates SDL3 display/window paths with wrappers for fullscreen and GL/vsync, overlapping with the introduced PG_* wrappers and SDL_SyncWindow usage.

Suggested labels

display, sdl3

Suggested reviewers

  • Starbuck5
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ankith26-sdl3-2

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between c7e9c15 and 9aeca32.

📒 Files selected for processing (3)
  • src_c/_pygame.h (2 hunks)
  • src_c/display.c (31 hunks)
  • src_c/window.c (8 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: Starbuck5
PR: pygame-community/pygame-ce#3573
File: src_c/_camera.c:129-131
Timestamp: 2025-08-30T21:11:00.196Z
Learning: When doing SDL2 to SDL3 compatibility changes, Starbuck5 prefers to maintain exact existing behaviors even when other improvements could be made, focusing solely on the compatibility aspect rather than mixing in behavioral fixes.
📚 Learning: 2025-08-30T21:11:00.196Z
Learnt from: Starbuck5
PR: pygame-community/pygame-ce#3573
File: src_c/_camera.c:129-131
Timestamp: 2025-08-30T21:11:00.196Z
Learning: When doing SDL2 to SDL3 compatibility changes, Starbuck5 prefers to maintain exact existing behaviors even when other improvements could be made, focusing solely on the compatibility aspect rather than mixing in behavioral fixes.

Applied to files:

  • src_c/display.c
🧬 Code graph analysis (1)
src_c/display.c (2)
src_c/base.c (1)
  • pg_GetDefaultWindow (1916-1920)
src_c/_pygame.h (1)
  • PG_GL_SetSwapInterval (384-388)
🔇 Additional comments (22)
src_c/window.c (4)

304-313: LGTM! Proper SDL3 boolean return handling

The conversion to handle SDL3's boolean return value for SDL_SetWindowFullscreen is correct, including the addition of SDL_SyncWindow for immediate effect.


349-349: Good addition of window sync for SDL3

Adding SDL_SyncWindow after fullscreen setup ensures the changes take immediate effect, maintaining consistency with SDL2 behavior.


382-382: Correct type change for SDL3 compatibility

Changing input_only from SDL_bool to int is appropriate since it's now used as a Python boolean via PyArg_ParseTupleAndKeywords.


434-436: Consistent SDL_SyncWindow additions

All the SDL_SyncWindow calls are properly guarded with SDL_VERSION_ATLEAST(3, 0, 0) and placed after window state changes. This ensures immediate synchronization with the windowing system in SDL3.

Based on the learnings provided, this follows the preferred approach of maintaining exact existing behaviors for SDL2 to SDL3 compatibility changes.

Also applies to: 444-446, 454-456, 759-761, 814-816, 857-859, 891-893

src_c/display.c (18)

282-286: Proper null window handling

Good defensive programming - checking if the window exists before accessing its flags prevents potential crashes.


467-472: Correct primary display handling for SDL3

The code properly handles SDL3's primary display API where display ID 0 has special meaning. The error checking when SDL_GetPrimaryDisplay() returns 0 is essential.


813-821: SDL3 boolean return value handling looks correct

The GL attribute setter properly handles SDL3's boolean return convention.


833-841: GL getter boolean handling is correct

The GL attribute getter properly handles SDL3's boolean return convention.


1140-1192: Comprehensive fullscreen wrapper implementation

The PG_SetWindowFullscreen function properly abstracts the differences between SDL2 and SDL3 fullscreen handling, including the boolean return values and window synchronization.


1270-1278: Primary display compatibility for SDL3

Good implementation of backwards compatibility - SDL2's display index 0 is properly mapped to SDL3's primary display.


1483-1491: Display bounds API adaptation

Correctly handles the different return conventions between SDL2 and SDL3 for SDL_GetDisplayUsableBounds.


1580-1584: Consistent use of PG_SetWindowFullscreen wrapper

All fullscreen state changes properly use the new wrapper function, maintaining consistency throughout the codebase.


1642-1661: Swap interval wrapper usage

Good use of the PG_GL_SetSwapInterval wrapper to handle SDL3's boolean return convention for vsync control.


1899-1901: Window synchronization points

All SDL_SyncWindow calls are properly placed after window state changes and correctly guarded with SDL3 version checks.

Also applies to: 2000-2002, 2794-2796


2030-2038: Primary display handling in mode_ok

Consistent implementation of the primary display compatibility layer for SDL3.


2065-2073: Smart compatibility fallback

The code cleverly uses the current display mode when the resolution matches, providing better SDL2 compatibility. This is a nice touch that maintains expected behavior.


2113-2121: Primary display handling in list_modes

Consistent primary display compatibility implementation.


2133-2139: Proper bpp fallback using current mode

Good use of current display mode for bits-per-pixel when not specified, maintaining SDL2 behavior.


2143-2157: Robust empty list handling

Excellent defensive programming - when SDL3 returns an empty display modes list (which SDL2 didn't), the code falls back to using the current mode. This maintains backwards compatibility.


3260-3527: Comprehensive fullscreen toggle implementation

The toggle_fullscreen function properly uses PG_SetWindowFullscreen throughout and adds SDL_SyncWindow at the end for SDL3. The implementation maintains compatibility across different rendering backends (GL, SDL_Renderer, software).


3605-3607: Display resize event synchronization

Proper addition of SDL_SyncWindow after window size changes in the resize event handler.


3841-3844: Message box return value handling

Correctly inverts the return check for SDL3's SDL_ShowMessageBox which returns true on success instead of 0.

@Starbuck5 Starbuck5 added the sdl3 label Sep 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants